import qs from "qs";
var token = uni.getStorageSync("token");
const post = function (url, data, success, fail, power, contentType, responseType = "text") {
  var header = {};
  // header["content-type"] = "application/json;charset=UTF-8";
  if (!!token) header["Authorization"] = token;
  uni.request({
    url,
    method: "POST",
    data,
    header,
    responseType,
    success(res) {
      if (res.statusCode == 200) {
        success && success(res.data);
      } else {
        fail && fail(res);
      }
      if (res.data.code == 403 || res.data.code == 401) {
        //拦截器，403 登陆过期
        uni.showToast({
          title: "登录失效，请重新登录",
          icon: "none",
        });
        setTimeout(function () {
          uni.clearStorage();
          uni.reLaunch({
            url: "/pages/login/index",
          });
        }, 1500);
      }
    },
    fail(res) {
      fail && fail(res);
    },
  });
};

const get = function(url, data, success, fail, power,contentType) {
	var header = {};
	uni.request({
		url,
		method: 'GET',
		data,
		header,
		success(res) {
			if (res.statusCode == 200) {
				success && success(res.data)
			} else {
				fail && fail(res)
			}
		},
		fail(res) {
			fail && fail(res)
		}
	})
}


module.exports = {
  // 请求方法
  post,
  get
};
